package cool.collection;

import java.io.ByteArrayOutputStream;
import java.util.Map;
import java.util.TreeMap;

public class TreeMapTest{
    public static void main(String args[]){
        Map<Empety,String> map=new TreeMap<Empety,String>();
        map.put(new Empety(100,"gaogao",5555),"不错的");
        map.put(new Empety(100,"gaogao",5532),"不错的");
        map.put(new Empety(100,"gaogao",5578),"不错的");
        for(Empety empety:map.keySet()){
            System.out.println(empety);
        }


    }
}
class Empety implements Comparable{
    int id;
    String name;
    int age;

    public Empety(int id, String name, int age) {
        this.id = id;
        this.name = name;
        this.age = age;
    }

    @Override
    public String toString() {
        return "Empety{" +
                "id=" + id +
                ", name='" + name + '\'' +
                ", age=" + age +
                '}';
    }

    @Override
    public  int compareTo(Object o) {
        Empety e=(Empety)o;
        if(this.id>e.id){
            return 1;
        }else if(this.id<e.id){
            return -1;
        }else{
            if(this.age>e.age){
                return 1;
            }else if(this.age==e.age){
                return 0;
            }else{
                return -1;
            }
        }

    }
}
